package cn.edu.xhu.library_management.area.mapper;

import cn.edu.xhu.library_management.area.entity.LmInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2022 - 08 - 28
 * @Description: 图书馆信息mapper接口
 */
public interface InfoMapper {

    /**
     * 查找所有图书馆信息
     * @return 图书馆信息集合
     */
    @Select("select *from lm_info;")
    @Results(id = "baseInfoResult",value = {
            @Result(id = true,column = "info_id",property = "id"),
            @Result(column = "info_name",property = "name"),
            @Result(column = "info_introduction",property = "introduction"),
            @Result(column = "info_floors",property = "floors")
    })
    public List<LmInfo> findAllInfos();

    /**
     * 通过图书馆ID查询图书馆
     * @param id 图书馆ID
     * @return 图书馆对象
     */
    @Select("select * from lm_info where info_id = #{id} ;")
    @ResultMap("baseInfoResult")
    public LmInfo findInfoById(Integer id);

    @Select("select *from lm_info where info_name = #{name}")
    @ResultMap("baseInfoResult")
    public LmInfo findInfoByName(String name);

    /**
     * 添加图书馆信息
     * @param info 图书馆对象
     * @return 返回受影响的行数
     */
    @Insert("insert into lm_info(info_name,info_introduction,info_floors) " +
            "values (#{name},#{introduction},#{floors})")
    public int addInfo(LmInfo info);

    /**
     * 修改图书馆信息
     * @param info 图书馆对象
     * @return 返回受影响的行数
     */
    public int updateInfo(LmInfo info);

    /**
     * 通过图书馆ID删除图书馆
     * @param id 图书馆ID
     * @return 返回受影响的行数
     */
    @Delete("delete from lm_info where info_id = #{id}")
    public int deleteInfoById(Integer id);
}
